﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyWcfRestLib.Files;
using MyWcfRestLib;

namespace MyWcfRestSvc
{
    class FileServiceAdapter
    {
        private readonly static FileServiceAdapter instance = new FileServiceAdapter();
        private FileServiceAdapter() { }
        public static FileServiceAdapter Instance { get { return instance; } }

        WcfService FileService;

        public bool Start(int port)
        {
            if (null == FileService)
            {
                FileService = new FileTransferService(port);
            }
            WindowsFirewallHelper.AddPort("LeonPort", port, FirewallProtocol.tcp);
            FileService.Start();

            return true;
        }

        public void Stop()
        {
            if (null != FileService)
            {
                FileService.Close();
            }
            WindowsFirewallHelper.DeletePort(8231, FirewallProtocol.tcp);
        }

        public ServiceConnectionInfo GetConnectionInfo()
        {
            if (null != FileService)
            {
                return FileService.ConnectionInfo;
            }
            else
            {
                return new ServiceConnectionInfo();
            }
        }

        public string GetConnectionInfoString()
        {
            if (null != FileService)
            {
                return FileService.ConnectionInfoJson;
            }
            else
            {
                return null;
            }
        }

    }
}
